﻿using System.Collections.Generic;
using Dsl.Ped.Common;
using Dsl.Ped.Controls.ProjectiveControl;
using Dsl.Ped.Editor.Messages;
using Dsl.Ped.Framework.Common;
using GalaSoft.MvvmLight.Messaging;

namespace Dsl.Ped.Editor
{
    /// <summary>
    /// Editor must be provided with the essential information like current containers, view modes, etc.
    /// This class wraps them all.
    /// </summary>
    public class EditorResources : ViewModelBase
    {
        #region Fields

        /// <summary>
        /// Currently selected view mode
        /// </summary>
        private ViewMode selectedViewMode;

        /// <summary>
        /// All available view modes
        /// </summary>
        private List<ViewMode> viewModes;

        /// <summary>
        /// All available projection contaienrs
        /// </summary>
        private List<IProjectionContainer> projectionContainers;

        /// <summary>
        /// Currently selected projection container
        /// </summary>
        private IProjectionContainer selectedProjectionContainer;

        /// <summary>
        /// Messenger used for the communication among the editor's modules
        /// </summary>
        private Messenger messenger;

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="EditorResources"/> class.
        /// </summary>
        /// <param name="messenger">The messenger for the communication among editor's modules</param>
        public EditorResources(Messenger messenger)
        {
            this.messenger = messenger;
        }

        #endregion

        #region Members

        /// <summary>
        /// Gets or sets the available <see cref="ViewModes"/> options
        /// </summary>
        public List<ViewMode> ViewModes
        {
            get { return viewModes; }
            set { 
                viewModes = value;
                this.RaisePropertyChanged(() => ViewModes);
            }
        }

        /// <summary>
        /// Gets or sets the current selected <see cref="ViewMode"/> option
        /// </summary>
        public ViewMode SelectedViewMode
        {
            get { return selectedViewMode; }
            set
            {
                selectedViewMode = value;
                this.RaisePropertyChanged(() => SelectedViewMode);
            }
        }

        /// <summary>
        /// Gets or sets all available projection containers of selected projective control
        /// </summary>
        public List<IProjectionContainer> ProjectionContainers
        {
            get
            {
                return projectionContainers;
            }
            set
            {
                projectionContainers = value;
                this.RaisePropertyChanged(() => ProjectionContainers);
            }
        }

        /// <summary>
        /// Gets or sets the currently selected projection container among <see cref="ProjectionContainers"/>
        /// </summary>
        public IProjectionContainer SelectedProjectionContainer
        {
            get
            {
                return selectedProjectionContainer;
            }
            set
            {
                selectedProjectionContainer = value;
                this.RaisePropertyChanged(() => SelectedProjectionContainer);
                
                messenger.Send(new ProjectionContainerChangedMessage(value));
            }
        }

        #endregion
    }
}
